package com.hailiao.beidou.message.bd.data

import com.hailiao.beidou.standard2.BDICI_Data
import com.hailiao.beidou.standard3.BDICP_Data

/**
 * 北斗卡数据
 * @Author d10ng
 * @Date 2023/11/17 11:11
 */
data class BDCardData(
    // 卡号
    var number: String = "",
    // 卡频度，单位秒
    var frequency: Int = 60,
    // 卡等级
    var level: Int = 0,
    // 可发送字节长度
    var sendByteSize: Int = 0,
)

fun BDICP_Data.toBDCardData() = BDCardData(
    number = this.address.toIntOrNull()?.let { if (it == 2031958 || it == 0) "" else this.address } ?: "",
    frequency = this.RDSSServiceFrequency,
    level = this.RDSSCommunicationLengthLevel.value,
    sendByteSize = this.RDSSCommunicationLengthLevel.bytes
)

fun BDICI_Data.toBDCardData() = BDCardData(
    number = this.address.toIntOrNull()?.let { if (it == 0) "" else this.address } ?: "",
    frequency = this.frequency,
    level = this.level,
    sendByteSize = 78
)

fun BDCardData.toBDDeviceStatusDataList() = listOf(
    BDDeviceStatusData(BDDeviceStatusData.Type.CARD, "卡号", number),
    BDDeviceStatusData(BDDeviceStatusData.Type.CARD_LEVEL, "卡等级", "${level}级"),
    BDDeviceStatusData(BDDeviceStatusData.Type.CARD_FREQUENCY, "卡频度", "${frequency}秒"),
)